<template>
  <div class="container">
    <van-button
      type="primary"
      size="large"
      @click="selectlocation"
    >获取值</van-button>
  </div>
</template>

<script>
// import Vue from 'vue'
const chooseLocation = requirePlugin('chooseLocation')
export default {
  components: {},

  data () {
    return {
      departure: ''
    }
  },
  onLoad (option) {
    // let continent = Object.keys(dist)
    // this.multiArray.push(continent)
    // this.multiArray.push(dist[continent[0]])
  },
  created () {
    console.log('test')
  },

  methods: {
    onShow () {
      const location = chooseLocation.getLocation() // 如果点击确认选点按钮，则返回选点结果对象，否则返回null
      console.log(location)
    },
    selectlocation () {
      var that = this

      wx.chooseLocation({
        success: function (res) {
          // success
          console.log(res)
          that.departure = res.name
        },

        fail: function () {
          // fail
        },

        complete: function () {
          // complete
        }
      })
    },
    loa () {
      const key = 'N75BZ-UTB3K-7GGJW-AVMIL-MDT36-RYFTQ' // 使用在腾讯位置服务申请的key
      const referer = 'sports' // 调用插件的app的名称
      const location = JSON.stringify({
        latitude: 39.89631551,
        longitude: 116.323459711
      })
      // const category = '生活服务,娱乐休闲'

      wx.navigateTo({
        url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}`,
        events: {
          // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
          acceptDataFromOpenedPage: function (data) {
            console.log(data)
          },
          someEvent: function (data) {
            console.log(data)
          }
        },
        success: function (res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
        }
      })
    }
  }
}
</script>

